package org.RSG.Interface;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

import org.RSG.Resources.*;

public class LayersPanel extends JPanel implements MouseListener
{
	private static final long serialVersionUID = 1L;
	public int selectedLayer = 0;
	public int lMax = 4;
	
	public LayersPanel()
	{
		super(true);
		this.addMouseListener(this);
	}
	
	public void paintComponent(Graphics g)
	{
		g.setColor(new Color(238, 238, 238));
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		boolean sel;
		
		for(int i = 0; i < 5; i++)
		{
			if(i - 1 == this.selectedLayer)
			{
				sel = true;
			} else {
				sel = false;
			}
			drawLayerCell(g, i - 1, "Layer " + i, sel, true);
		}
	}
	
	public void drawLayerCell(Graphics g, int y_offset, String LayerName, boolean Selected, boolean Visible)
	{
		y_offset *= 25;
		//Check If Layer is Highlighted
		if(Selected)
		{
			g.setColor(new Color(49, 106, 197));
			g.fillRect(0, y_offset, this.getWidth(), 25);
		}
		//Draw Layer Box
		g.setColor(Color.BLACK);
		g.drawLine(0, y_offset, this.getWidth(), y_offset);
			if(Selected)
			{
				g.setColor(Color.WHITE);
			}
			g.drawString(LayerName, 20, y_offset + 17);
			if(Visible)
			{
				g.drawImage(new Icons().GetIcon(1), 3, y_offset + 5, null);
			} else {
				g.drawImage(new Icons().GetIcon(2), 3, y_offset + 5, null);
			}
			g.setColor(Color.BLACK);
		g.drawLine(0, y_offset + 25, this.getWidth(), y_offset + 25);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		if(e.getButton() == 1)
		{
			//System.out.println(e.getX());
			//System.out.println(e.getY());
			int nsel = Math.round(e.getY() / 25);
			//System.out.println(nsel);
			if(nsel < this.lMax)
			{
				this.selectedLayer = nsel;
			}
			this.repaint();
		}
	}
}